package com.xiong.ai.strategy;

import com.xiong.ai.exception.BusinessException;
import com.xiong.ai.util.SpringContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: ai
 * @description:
 * @author: Mr.熊
 * @create: 2024-05-31 11:24
 **/
@Component
public class FileStrategyProcessor {

    protected final Logger LOGGER = LoggerFactory.getLogger(this.getClass());

    public static Map<String, Class<? extends FileStrategy>> map = new HashMap<>();

    static {
        //word处理
        map.put(".doc", WordStrategy.class);
        map.put(".docx", WordStrategy.class);
        //pdf处理
        map.put(".pdf", PdfStrategy.class);
    }

    public FileStrategy selectFileStrategy(String fileType) {
        LOGGER.info("读取文件内容，文件类型为：{}", fileType);
        if (fileType == null || !map.containsKey(fileType)) {
            throw new BusinessException("暂不支持该文件类型");
        }
        return SpringContextUtil.getBean(map.get(fileType));
    }

}
